<?php
class MembersController extends AppController {

    var $name = 'Members';

    function admin_index() {
        $this->Member->recursive = 0;
        $this->set('members', $this->paginate());
    }

    function admin_view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid member', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('member', $this->Member->read(null, $id));
    }

    function admin_add() {
        if (!empty($this->data)) {
            $this->Member->create();
            if ($this->Member->save($this->data)) {
                $this->Session->setFlash(__('The member has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The member could not be saved. Please, try again.', true));
            }
        }
    }

    function admin_edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid member', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Member->save($this->data)) {
                $this->Session->setFlash(__('The member has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The member could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Member->read(null, $id);
        }
    }

    function admin_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for member', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->Member->delete($id)) {
            $this->Session->setFlash(__('Member deleted', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Session->setFlash(__('Member was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }
}
?>